import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { SpecificationModel } from './specification.model';
import { AllDto } from "@/module/specification/specification.dto";
import { EvaluationCategory } from "common/utils/data";

@Injectable()
export class SpecificationService {
  constructor(
    @InjectRepository(SpecificationModel)
    private readonly specificationModelRepository: Repository<SpecificationModel>,
  ) {}

  async all(query: AllDto): Promise<SpecificationModel[]> {
    const where: {
      category?: EvaluationCategory;
    } = {};

    if(query.category){
      where.category = query.category
    }

    return this.specificationModelRepository.find({
      select: ['uuid', 'name', 'desc', 'sort','extra','valueType', 'openSearch', 'category'],
      where,
      order: {
        sort: 'ASC',
        id: 'DESC',
      },
    });
  }
}
